home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / ELYVER10.ZIP / TUT01NEW.ZIP / TUT1.TXT < prev   
Encoding:
Text File  |  1994-10-21  |  11.1 KB  |  289 lines

  1.  
  2.                    ╒═══════════════════════════════╕
  3.                    │         W E L C O M E         │
  4.                    │  To the VGA Trainer Program   │ │
  5.                    │              By               │ │
  6.                    │      DENTHOR of ASPHYXIA      │ │ │
  7.                    │      (updated by Snowman)     │ │ │
  8.                    ╘═══════════════════════════════╛ │ │
  9.                      ────────────────────────────────┘ │
  10.                        ────────────────────────────────┘
  11.  
  12.                       --==[ PART 1 : The Basics]==--
  13.  
  14. ■ Introduction
  15.  
  16. Hi there! This is Denthor of ASPHYXIA, AKA Grant Smith. This training
  17. program is aimed at all those budding young demo coders out there. I am
  18. assuming that the reader is fairly young, has a bit of basic Std. 6 math
  19. under his belt, has done a bit of programming before, probably in BASIC,
  20. and wants to learn how to write a demo all of his/her own.
  21.  
  22. This I what I am going to do. I am going to describe how certain routines
  23. work, and even give you working source code on how you do it. The source
  24. code will assume that you have a VGA card that can handle the
  25. 320x200x256 mode. I will also assume that you have Turbo Pascal 6.0 or
  26. above (this is because some of the code will be in Assembly language,
  27. and Turbo Pascal 6.0 makes this incredibly easy to use).  [In addition,
  28. C++ source has been included, so you now have a choice].  By the end of 
  29. the first "run" of sections, you will be able to code some cool demo stuff
  30. all by yourself. The info you need, I will provide to you, but it will be
  31. you who decides on the most spectacular way to use it.
  32.  
  33. Why not download some of our demos and see what I'm trying to head you
  34. towards.
  35.  
  36. [Note: things in brackets have been added by Snowman.  The original text
  37. has remained mostly unaltered except for the inclusion of C++ material]
  38.  
  39. I will be posting one part a week on the Mailbox BBS. I have the first
  40. "run" of sections worked out, but if you want me to also do sections on
  41. other areas of coding, leave a message to Grant Smith in private E-Mail,
  42. or start a conversation here in this conference. I will do a bit of
  43. moderating of a sort, and point out things that have been done wrong.
  44.  
  45. In this, the first part, I will show you how you are supposed to set up
  46. your Pascal or C++ program, how to get into 320x200x256 graphics mode 
  47. without a BGI file, and various methods of putpixels and a clearscreen 
  48. utility.
  49.  
  50. NOTE : I drop source code all through my explanations. You needn't try
  51.        to grab all of it from all over the place, at the end of each part I
  52.        add a little program that uses all the new routines that we have
  53.        learned. If you do not fully understand a section, leave me
  54.        private mail telling me what you don't understand or asking how I
  55.        got something etc, and I will try to make myself clearer. One
  56.        last thing : When you spot a mistake I have made in one of my
  57.        parts, leave me mail and I will correct it post-haste.  However, I
  58.        do not know C++ currently, so if you have trouble with that source,
  59.        contact Christopher Mann instead.
  60.  
  61. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  62. ■ Disclaimer
  63.  
  64. Hi again, sorry that I have to add this, but here goes.  All source code
  65. obtained from this series of instruction programs is used at your own
  66. risk.  Denthor and the ASPHYXIA demo team hold no responsibility for any
  67. loss or damage suffered by anyone through the use of this code.  Look
  68. guys, the code I'm going to give you has been used by us before in
  69. Demos, Applications etc, and we have never had any compliants of machine
  70. damage, but if something does go wrong with your computer, don't blame
  71. us.  Sorry, but that's the way it is.
  72.  
  73. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  74. ■ The MCGA mode and how you get into it in Pascal or C++ without a BGI
  75.  
  76. Lets face it. BGI's are next to worthless for demo coding. It is
  77. difficult to find something that is slower then the BGI units for doing
  78. graphics. Another thing is, they wern't really meant for 256 color
  79. screens anyhow. You have to obtain a specific external 256VGA BGI to get
  80. into it in Pascal, and it just doesn't make the grade.
  81.  
  82. So the question remains, how do we get into MCGA 320x200x256 mode in
  83. Pascal or C++ without a BGI?  The answer is simple : Assembly language.
  84. Obviously assembly language has loads of functions to handle the VGA
  85. card, and this is just one of them. If you look in Norton Gides to
  86. Assembly Language, it says this ...
  87.  
  88. ──────────────────────────────────────────────────────────────────────────
  89. INT 10h,  00h (0)        Set Video Mode
  90.  
  91.     Sets the video mode.
  92.  
  93.        On entry:      AH         00h
  94.                       AL         Video mode
  95.  
  96.        Returns:       None
  97.  
  98.        Registers destroyed:      AX, SP, BP, SI, DI
  99. ──────────────────────────────────────────────────────────────────────────
  100.  
  101. This is all well and good, but what does it mean? It means that if you
  102. plug in the video mode into AL and call interrupt 10h, SHAZAM! you are
  103. in the mode of your choice. Now, the MCGA video mode is mode 13h, and
  104. here is how we do it:
  105.  
  106. [PASCAL]
  107.  
  108.   Procedure SetMCGA;
  109.   BEGIN
  110.     asm
  111.           mov     ax,0013h
  112.           int     10h
  113.     end;
  114.   END;
  115.  
  116. [C++]
  117.  
  118.   void SetMCGA() {
  119.     _AX = 0x0013;
  120.     geninterrupt (0x10);
  121.   }
  122.  
  123.  
  124. There you have it! One call to that procedure/function, and BANG you are in
  125. 320x200x256 mode. We can't actually do anything in it yet, so to go back
  126. to text mode, you make the video mode equal to 03h, as seen below :
  127.  
  128. [PASCAL]
  129.  
  130.   Procedure SetText;
  131.   BEGIN
  132.     asm
  133.           mov     ax,0003h
  134.           int     10h
  135.     end;
  136.   END;
  137.  
  138. [C++]
  139.  
  140.   void SetText() {
  141.     _AX = 0x0003;
  142.     geninterrupt (0x10);
  143.   }
  144.  
  145.  
  146. BANG! We are back in text mode! Now, cry all your enquiring minds, what
  147. use is this? We can get into the mode, but how do we actually SHOW
  148. something on the screen? For that, you must move onto the next section
  149. ....
  150.  
  151. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  152. ■  Clearing the screen to a specific color
  153.  
  154. Now that we are in MCGA mode, how do we clear the screen. The answer is
  155. simple : you must just remember that the base adress of the screen is
  156. a000h. From a000h, the next 64000 bytes are what is actually displayed on
  157. the screen (Note : 320 * 200 = 64000). So to clear the screen, you just use
  158. the fillchar command like so :
  159.  
  160. [PASCAL]
  161.  
  162.       FillChar (Mem [$a000:0],64000,Col);
  163.  
  164. [C++]
  165.      
  166.       memset(vga, Col, 0xffff);  // "vga" is a pointer to address 0xa000
  167.  
  168. What the mem command passes the Segment base and the Offset of a part of
  169. memory : in this case the screen base is the Segment, and we are starting
  170. at the top of the screen; Offset 0. The 64000 [0xffff] is the size of the
  171. screen (see above), and Col is a value between 0 and 255, which represents
  172. the color you want to clear the screen to.
  173.  
  174. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  175. ■  Putting a pixel on the screen (two different methoods)
  176.  
  177. If you look in Norton Guides about putting a pixel onto the screen, you
  178. will see this  :
  179.  
  180. ──────────────────────────────────────────────────────────────────────────
  181.     Writes a pixel dot of a specified color at a specified screen
  182.     coordinate.
  183.  
  184.     On entry:      AH         0Ch
  185.                    AL         Pixel color
  186.                    CX         Horizontal position of pixel
  187.                    DX         Vertical position of pixel
  188.                    BH         Display page number (graphics modes with more
  189.                               than 1 page)
  190.  
  191.     Returns:       None
  192.  
  193.     Registers destroyed:      AX, SP, BP, SI, DI
  194. ──────────────────────────────────────────────────────────────────────────
  195.  
  196. As seen from our SetMCGA example, you would write this by doing the following:
  197.  
  198. [PASCAL]
  199.  
  200.   Procedure INTPutpixel (X,Y : Integer; Col : Byte);
  201.   BEGIN
  202.     asm
  203.        mov        ah,0Ch
  204.        mov        al,[col]
  205.        mov        cx,[x]
  206.        mov        dx,[y]
  207.        mov        bx,[1]
  208.        int        10h
  209.     end;
  210.   END;
  211.  
  212. [C++]
  213.  
  214.   void INTPutpixel(int x, int y, unsigned char Col) {
  215.     _AH = 0x0C;
  216.     _AL = Col;
  217.     _CX = x;
  218.     _DX = y;
  219.     _BX = 0x01;
  220.     geninterrupt (0x10);
  221.   }
  222.  
  223.  
  224. The X would be the X-Coordinate, the Y would be the Y-Coordinate, and the Col
  225. would be the color of the pixel to place.  Note that MCGA has 256 colors,
  226. numbered 0 to 255. The startoff pallette is pretty grotty, and I will show
  227. you how to alter it in my next lesson, but for now you will have to hunt for
  228. colors that fit in for what you want to do.  Luckily, a byte is 0 to 255
  229. [in C++ syntax, "byte" = "unsigned char"], so that is what we pass to the col
  230. variable. Have a look at the following.
  231.  
  232.     CGA = 4 colours.
  233.     4x4 = 16
  234.     EGA = 16 colors.
  235.     16x16 = 256
  236.     VGA = 256 colors.
  237.     Therefore an EGA is a CGA squared, and a VGA is an EGA squared ;-)
  238.  
  239. Anyway, back to reality. Even though the above procedure/function is written
  240. in assembly language, it is slooow. Why? I hear your enquiring minds cry.
  241. The reason is simple : It uses interrupts (It calls INT 10h). Interrupts are
  242. sloooow ... which is okay for getting into MCGA mode, but not for trying
  243. to put down a pixel lickety-split. So, why not try the following ...
  244.  
  245. [PASCAL]
  246.  
  247.   Procedure MEMPutpixel (X,Y : Integer; Col : Byte);
  248.   BEGIN
  249.     Mem [VGA:X+(Y*320)]:=Col;
  250.   END;
  251.  
  252. [C++]
  253.  
  254.   void MEMPutpixel (int x, int y, unsigned char Col) {
  255.     memset(vga+x+(y*320),Col,1);
  256.   }
  257.  
  258.  
  259. The Mem/memset command, as we have seen above, allows you to point at a 
  260. certain point in memory ... the starting point is a000h, the base of the 
  261. VGA's memory, and then we specify how far into this base memory we start.
  262.  
  263. Think of the monitor this way. It starts in the top left hand corner at
  264. 0. As you increase the number, you start to move across the screen to your
  265. right, until you reach 320. At 320, you have gone all the way across the
  266. screen and come back out the left side, one pixel down. This carries on
  267. until you reach 63999, at the bottom right hand side of the screen. This
  268. is how we get the equation X+(Y*320). For every increased Y, we must
  269. increment the number by 320. Once we are at the beginning of the Y line
  270. we want, we add our X by how far out we want to be. This gives us the
  271. exact point in memory that we want to be at, and then we set it equal to
  272. the pixel value we want.
  273.  
  274. The MEM methood of putpixel is much faster, and it is shown in the sample
  275. program at the end of this lesson. The ASPHYXIA team uses neither putpixel;
  276. we use a DMA-Straight-To-Screen-Kill-Yer-Momma-With-An-Axe type putpixel
  277. which is FAST. We will give it out, but only to those of you who show us
  278. you are serious about coding. If you do do anything, upload it to me,
  279. I will be very interested to see it. Remember : If you do glean anything
  280. from these training sessions, give us a mention in your demos and UPLOAD
  281. YOUR DEMO TO US!
  282.  
  283. Well, after this is the sample program; have fun with it, UNDERSTAND it,
  284. and next week I will start on fun with the pallette.
  285.  
  286. See you all later,
  287.     - Denthor
  288.  
  289.